package org.analyzer.ansj;

import java.io.IOException;
import java.io.Reader;
import java.util.Map;

import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.util.ResourceLoader;
import org.apache.lucene.analysis.util.ResourceLoaderAware;
import org.apache.lucene.analysis.util.TokenizerFactory;
import org.apache.lucene.util.AttributeFactory;


public class AnsjTokenizerFactory extends TokenizerFactory implements ResourceLoaderAware {

	private int analysisType = 0;
	private boolean rmPunc = true;
	private ResourceLoader loader; 

	private String conf = null;


	public AnsjTokenizerFactory(Map<String, String> args) {
		super(args);
		assureMatchVersion();
		analysisType = getInt(args, "analysisType", 0);
		rmPunc = getBoolean(args, "rmPunc", true);
		conf = get(args, "conf");
	}

	//TODO 扩展词库 采用默认加载方法 
	//读取classPath中 library.properties文件
	public void inform(ResourceLoader loader) throws IOException {
//		System.out.println(":::ansj:::inform::::::::::::::::::::::::" + conf);
//		this.loader = loader;
//		this.initFiles();
	}

	@Override
	public Tokenizer create(AttributeFactory factory, Reader input) {
		return new AnsjTokenizer(input, analysisType, rmPunc);
	}

}